﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SaleWebsite.Models;
using System.Data;

namespace SaleWebsite.Controllers
{
    public class GroupController : Controller
    {
        //
        // GET: /Group/

        public ActionResult Index()
        {
            
            return View(Group.GetAll());
        }
        public ActionResult insert(string group)
        {

            Group item = new Group(0, group);
         ulong id=   item.Insert();
         item.Id = id;
         return PartialView("group_row", item);
            
            
        }
        public JsonResult delete(ulong id)
        {
            Group item = new Group(id, "");
            if (item.Delete()>0)
            {
                return Json(new {status="success" });
            }else
            {
                return Json(new { status = "not" });
            }
            
        }
        public JsonResult Save_Group(ulong id,string name)
        {
            try
            {
                Group item = new Group(id, name);
                if (item.Save()>0)
                {
                    return Json(new { status = "success" });
                }else
                {
                    return Json(new { error = "update Faile" });
                }
            }
            catch (System.Exception ex)
            {
                return Json(new { error = ex.Message });
            }
        }

    }
}
